<template>
  <div class="zoom-controls">
    <button @click="zoomIn">+</button>
    <button @click="zoomOut">-</button>
  </div>
</template>

<script setup>
import { defineProps } from 'vue'

const props = defineProps({
  map: {
    type: Object, // OpenLayers 地图实例
    required: true,
  },
})

const zoomIn = () => {
  if (props.map) {
    const view = props.map.getView()
    view.animate({ zoom: view.getZoom() + 1, duration: 250 })
  }
}

const zoomOut = () => {
  if (props.map) {
    const view = props.map.getView()
    view.animate({ zoom: view.getZoom() - 1, duration: 250 })
  }
}
</script>

<style scoped>
.zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 1001; /* 确保它在地图上方 */
}

.zoom-controls button {
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 30px;
  height: 30px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.zoom-controls button:hover {
  background-color: #f0f0f0;
}
</style>
